<template>
	<view>
		<u-list
			v-if="list.length > 0"
		>
			<u-list-item
				v-for="(item, index) in list"
				:key="index"
			>
				<u-collapse
				  >
					<u-collapse-item
					  :title="item.pname"
					>
					<text slot="value" style="font-size: 25rpx;">{{item.mydate || item.bxdate}}</text>
					<view class="" v-if="id == 'wx'">
						<view class="">维修进度：{{item.pstate}}</view>
						<view class="">维修时间：{{item.bxdate}}</view>
						<view class="">规格参数：{{item.canshu}}</view>
						<view class="">维修级别：{{item.punit}}</view>
						<view class="">维修描述：{{item.ptype}}</view>
						<view class="">估价：{{item.pprice}}</view>
						<view class="">数量：{{item.num}}</view>
						<view class="">维修人：{{item.myuser}}</view>
					</view>
					<view class="" v-else-if="id == 'by'">
						<view class="">保养日期：{{item.mydate}}</view>
						<view class="">保养记录：{{item.pbz}}</view>
						<view class="">保养人：{{item.myuser}}</view>
						<view class="">保养描述：{{item.ptype}}</view>
						<view class="">估价：{{item.pprice}}</view>
						<view class="">级别：{{item.punit}}</view>
					</view>
					<view class="" v-else>
						<view class="">数量：{{item.num}}</view>
						<view class="">规格参数：{{item.canshu}}</view>
						<view class="">品牌：{{item.pinpai}}</view>
						<view class="">单价：{{item.pprice}}</view>
						<view class="">单位：{{item.punit}}</view>
						<view class="">规格：{{item.ptype}}</view>
					</view>
					</u-collapse-item>
				</u-collapse>
			</u-list-item>
		</u-list>
		<no-data v-else></no-data>
	</view>
</template>

<script>
	import _custom from '../../../../common/_custom.js'
	import NoData from '@/components/custom/no-data/no-data.vue'
	
	export default {
		components: {
			NoData
		},
		data() {
			return {
				id: '',
				device: {},
				list: [],
			}
		},
		onLoad(option) {
			let data = JSON.parse(option.data);
			this.id = data.id;
			this.device = data.device;
			let title = ''
			switch(this.id) {
				case 'wx':
				 this.getDeviceWeiXiuList();
				 title = '维修历史'
				 break;
				case 'by':
				 this.getDeviceBaoYangList();
				 title = '保养历史'
				 break;
				case 'bj':
				 this.getDeviceBeiJianList();
				 title = '备品备件'
				 break;
			}
			uni.setNavigationBarTitle({
				title: title
			});
			uni.$on('wx-list',(res) => {
				if(res.length > 0 && Object.keys(res[0]).length > 0) {
					this.list = res
				} else {
					this.list = []
				}
			})
			uni.$on('by-list',(res) => {
				if(res.length > 0 && Object.keys(res[0]).length > 0) {
					this.list = res
				} else {
					this.list = []
				}
			})
			uni.$on('bj-list',(res) => {
				if(res.length > 0 && Object.keys(res[0]).length > 0) {
					this.list = res
				} else {
					this.list = []
				}
			})
		},
		methods: {
			getDeviceWeiXiuList() {
				_custom.getDataJava({
					name: 'wx-list',
					apiname: 'getDeviceWeiXiuList',
					apiparam: {
						devicecode: this.device.aname,
					},
				})
			},
			getDeviceBaoYangList() {
				_custom.getDataJava({
					name: 'by-list',
					apiname: 'getDeviceBaoYangList',
					apiparam: {
						devicecode: this.device.aname,
					},
				})
			},
			getDeviceBeiJianList() {
				_custom.getDataJava({
					name: 'bj-list',
					apiname: 'getDeviceBeiJianList',
					apiparam: {
						devicecode: this.device.aname,
					},
				})
			},
		}
	}
</script>

<style>

</style>
